<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="/js/jquery.leanModal.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script language="javascript"> 
function transfer(date_begin,date_end){

	window.location.href = 'http://<?php echo WEB_IP?>/repairparts/repair-wizard-new-add-stock-lost/date_begin/'+ date_begin + '/date_end/' + date_end + '/next/yes';
}
</script>
<style type="text/css">
/* <![CDATA[ */

table, td
{
    border-color: #666;
    border-style: solid;
}
table, th
{
    border-color: #666;
    border-style: solid;
}

table
{
    border-width: 0 0 1px 1px;
    border-spacing: 0;
    border-collapse: collapse;
}

td
{
    margin: 0;
    padding: 8px;
    border-width: 1px 1px 0 0;
}
th
{
    margin: 0;
    padding: 8px;
    border-width: 1px 1px 0 0;
}

/* ]]> */
</style>

</head>

<body style="font-family:Arial, Helvetica, sans-serif;">
</table>



<?php 
$totalBonus = 0;

$staff = new Model_DbTable_Roster_Stafflogindetail();
$rParts = new Model_DbTable_Pr_Prproducts();
$rPartsRecord = new Model_DbTable_Repairstatusrecord();

?>
<h3>Problem List</h3>
<?php foreach ($this->list as $shop => $value){$i = 1;?>
<h3><?php echo $shop?></h3>
<table cellspacing="0" cellpadding="10" style="font-size:12px;">
  <tr>
  	<th rowspan="2" scope="col" style="width:50px;">No.</th>
  	<th rowspan="2" scope="col" style="width:100px;">Repair Shop</th>
    <th rowspan="2" scope="col" style="width:150px;">Repair Staff</th>
    <th rowspan="2" scope="col">Job ID</th>
    <th rowspan="2" scope="col" style="width:200px;">Finish Date</th>
    <th rowspan="2" scope="col">Mobile Model</th>
    <th colspan="3" scope="col">Quotes &amp; Invoices</th>
    <th colspan="4" scope="col">Parts and Cost</th>
    <th colspan="4" scope="col">Policy</th>
  </tr>
  <tr>
    <td align="center" style="">Quote</td>
    <td align="center" style="width:120px;">Invoices</td>
    <td align="center">APOS Amount</td>
    <td align="center" style="width:60px;" >Part</td>
    <td align="center" style="width:60px;" >Unit Cost</td>
    <td align="center" style="width:60px;" >Unit</td>
    <td align="center" style="width:60px;" >Parts Cost</td>
    <td align="center" style="width:60px;" >Cust Parts</td>
  </tr>
<?php foreach($value as $k=>$v){
	if($v['policy_custparts'] == 0){
?>    
	<tr>
	<td rowspan="2"><?php echo $i++;?></td>
    <td rowspan="2" align="center"><?php 
    		echo $v['shop_code'];
		// cal culate bonus 
    	?></td>
    <td rowspan="2" align="center">
    <?php 			
		$staffRow = $staff->getDetail($v["repair_staff"]);
		echo ucwords(Model_EncryptHelper::getSslpassword($staffRow["n"]));
		echo " (".ucwords($staffRow["ni"]).")";	
	?>
    </td>
    <td rowspan="2" align="center"><?php echo $v["id_job"]?></td>
    <td align="center"><?php echo $v["date_start"]?> to <?php echo substr($v["time_record"],0,10);?></td>
    <td rowspan="2" align="center"><?php echo $v["mobile_model"]?></td>
    <td rowspan="2" align="center"> $ <?php echo $v["quot_price"]?></td>
    <td>[1] : <?php echo ($v["invoice_no"]!="")?ucwords($v["invoice_no"]):" - ";?></td>
    <td rowspan="2" align="center"
    <?php 
	$totalInvoice = 0;
	if($v["invoice_no"]== $v["invoice_no2"]){
		$totalInvoice = $v["invoice_amt"];
		}
	else{
		$totalInvoice = $v["invoice_amt"] + $v["invoice_amt2"] ;
		}	
	if($totalInvoice ==0 ){
	?>
     bgcolor="#FFD9D9"
     <?php }?>
     > $ <?php echo $totalInvoice;?></td>
    <td colspan="4" rowspan="2" style="padding:0px; vertical-align:top;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <?php 
	$totalCost = $v["part_sum"][1];
	foreach($v["part_sum"][0] as $part){
		$singleCost = $part[2] * $part[1];
	?>	
      <tr>
        <td  style="width:60px;" ><?php echo $part[0];?></td>
        <td align="center"  style="width:60px;" > $ <?php echo $part[2]?></td>
        <td align="center"  style="width:60px;" > x <?php echo $part[1];?></td>
        <td align="center"  style="width:60px;" >$ <?php echo $singleCost;?></td>
      </tr>		
	<?php	
		}
	?>
    <tr>
    <td colspan="3" align="right">Sub Total:
    </td>
    <td <?php if ($totalInvoice < $totalCost){ ?>
     bgcolor="red"
     <?php }?>> $ <?php echo $totalCost;?></td>
    </tr>
    </table></td>
	<td rowspan = "2"><?php echo ($v['policy_custparts'] != 0)?
	'<img src="/images/yes20.jpg" />'
	:
	'<img src="/images/no20.jpg" />';?></td>
  </tr>
    <tr>
      <td align="center"> Record By :[<?php echo $v["staff_record"]?>]</td>
      <td>[2] : <?php echo ($v["invoice_no2"]!="")?ucwords($v["invoice_no2"]):" - ";?></td>
    </tr>


<?php }}?> 
<?php foreach($value as $k=>$v){
	if($v['policy_custparts'] != 0){
?>    
	<tr>
	<td rowspan="2"><?php echo $i++;?></td>
    <td rowspan="2" align="center"><?php 
    		echo $v['shop_code'];
		// cal culate bonus 
    	?></td>
    <td rowspan="2" align="center">
    <?php 			
		$staffRow = $staff->getDetail($v["repair_staff"]);
		echo ucwords(Model_EncryptHelper::getSslpassword($staffRow["n"]));
		echo " (".ucwords($staffRow["ni"]).")";	
	?>
    </td>
    <td rowspan="2" align="center"><?php echo $v["id_job"]?></td>
    <td align="center"><?php echo $v["date_start"]?> to <?php echo substr($v["time_record"],0,10);?></td>
    <td rowspan="2" align="center"><?php echo $v["mobile_model"]?></td>
    <td rowspan="2" align="center"> $ <?php echo $v["quot_price"]?></td>
    <td>[1] : <?php echo ($v["invoice_no"]!="")?ucwords($v["invoice_no"]):" - ";?></td>
    <td rowspan="2" align="center"
    <?php 
	$totalInvoice = 0;
	if($v["invoice_no"]== $v["invoice_no2"]){
		$totalInvoice = $v["invoice_amt"];
		}
	else{
		$totalInvoice = $v["invoice_amt"] + $v["invoice_amt2"] ;
		}	
	if($totalInvoice ==0 ){
	?>
     bgcolor="#FFD9D9"
     <?php }?>
     > $ <?php echo $totalInvoice;?></td>
    <td colspan="4" rowspan="2" style="padding:0px; vertical-align:top;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <?php 
	$totalCost = $v["part_sum"][1];
	foreach($v["part_sum"][0] as $part){
		$singleCost = $part[2] * $part[1];
	?>	
      <tr>
        <td  style="width:60px;" ><?php echo $part[0];?></td>
        <td align="center"  style="width:60px;" > $ <?php echo $part[2]?></td>
        <td align="center"  style="width:60px;" > x <?php echo $part[1];?></td>
        <td align="center"  style="width:60px;" >$ <?php echo $singleCost;?></td>
      </tr>		
	<?php	
		}
	?>
    <tr>
    <td colspan="3" align="right">Sub Total:
    </td>
    <td <?php if ($totalInvoice < $totalCost){ ?>
     bgcolor="red"
     <?php }?>> $ <?php echo $totalCost;?></td>
    </tr>
    </table></td>
	<td rowspan = "2"><?php echo ($v['policy_custparts'] != 0)?
	'<img src="/images/yes20.jpg" />'
	:
	'<img src="/images/no20.jpg" />';?></td>
  </tr>
    <tr>
      <td align="center"> Record By :[<?php echo $v["staff_record"]?>]</td>
      <td>[2] : <?php echo ($v["invoice_no2"]!="")?ucwords($v["invoice_no2"]):" - ";?></td>
    </tr>


<?php }}?> 
    
</table>
<?php }?>

</body>
</html>